package com.glsc.ngateway.platform.config;

import com.glsc.ngateway.common.oc.config.OcDataSourceDefConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @Author: zzp
 * @Date: 20200527
 * @Desc: 多DataSource配置
 */

@Configuration
@Import(OcDataSourceDefConfig.class)
public class DataSourceDefConfig {
    private static Logger logger = LoggerFactory.getLogger(DataSourceDefConfig.class);

    public static final String DS_MYSQL = "datasourceMysql";
    public static final String DS_MYSQL_CMDB = "datasourceMysqlCmdb";
//    public static final String DS_MYSQL_OC = "datasourceMysqlOc";
    public static final String DS_ORACLE = "datasourceOracle";

    @Primary
    @Bean(name = DS_MYSQL)
    @ConfigurationProperties("spring.datasource.mysql")
    public DataSource datasourceMysql() {
        DataSource dataSource = DataSourceBuilder.create().build();
        return dataSource;
    }

    @Bean(name = DS_MYSQL_CMDB)
    @ConfigurationProperties("spring.datasource.mysqlcmdb")
    public DataSource datasourceMysqlCmdb() {
        DataSource dataSource = DataSourceBuilder.create().build();
        return dataSource;
    }

//    @Bean(name = DS_MYSQL_OC)
//    @ConfigurationProperties("spring.datasource.mysqloc")
//    public DataSource datasourceMysqlOc() {
//        return DataSourceBuilder.create().build();
//    }

    @Bean(name = DS_ORACLE)
    @ConfigurationProperties("spring.datasource.oracle")
    public DataSource datasourceOracle() {
        return DataSourceBuilder.create().build();
    }
//
//    @Bean(name = "namedJdbcTemplateEcology")
//    NamedParameterJdbcTemplate namedParameterJdbcTemplate() {
//        return new NamedParameterJdbcTemplate(datasourceOracle());
//    }
}